package main

import (
	"fmt"
	"time"
)

func producer(producer_name string, ch chan<- int, len int) {
	for i := 0; i < len; i++ {
		fmt.Println("producer--", producer_name, ":", i)
		ch <- i
		time.Sleep(1 * time.Second)
	}
}
func consumer(cname string, ch <-chan int) {
	for i := range ch {
		fmt.Println("consumer--", cname, ":", i)
	}
	fmt.Println("ch chose.")
}
func main() {
	ch := make(chan int)
	go producer("producer 1", ch, 5)
	go producer("producer 2", ch, 5)
	go consumer("consumer 1", ch)
	go consumer("consumer 2", ch)
	time.Sleep(10 * time.Second)
	close(ch)
	time.Sleep(10 * time.Second)

}
